<?php

namespace liketp\console\command;

use liketp\console\BaseCommand;

class Serve extends BaseCommand
{
    protected $defaultOptions = [
        '--host' => [
            'type' => 'string',
            'default' => 'localhost'
        ],
        '--port' => [
            'type' => 'number',
            'default' => 8090,
        ]
    ];

    public function exec()
    {
        $host = $this->option('host');
        $port = $this->option('port');
        $root = app()->getEntrancePath();
        //$route = dirname(__DIR__) . DS . 'route.php';
        $route = '';
        $cmd = sprintf('php -S %s:%d -t %s %s', $host, $port, $root, $route);

        echo $cmd . PHP_EOL;
        ob_flush();

        passthru($cmd);
    }
}
